﻿using Microsoft.EntityFrameworkCore;
using Naruto.TaskManagement.Entitys.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace Naruto.TaskManagement.Entitys
{
    /// <summary>
    /// 授权中心的上下文
    /// </summary>
    public abstract class AuthCenterAbstractContext : DbContext
    {
        public AuthCenterAbstractContext(DbContextOptions options)
           : base(options)
        {
        }

        public virtual DbSet<User> User { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>(entity =>
            {
                entity.HasIndex(e => e.Password)
                    .HasName("Index_Password");

                entity.HasIndex(e => e.UserName)
                    .HasName("Index_UserName");

                entity.HasIndex(e => e.Vaild)
                    .HasName("Index_Vaild");

                entity.Property(e => e.Id)
                    .HasComment("主键")
                    .ValueGeneratedNever();

                entity.Property(e => e.CreateTime)
                    .HasColumnType("datetime")
                    .HasComment("创建时间");

                entity.Property(e => e.Email)
                    .IsRequired()
                    .HasColumnType("varchar(255)")
                    .HasDefaultValueSql("''")
                    .HasComment("邮箱")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_0900_ai_ci");

                entity.Property(e => e.HeardImgUrl)
                    .IsRequired()
                    .HasColumnType("varchar(255)")
                    .HasDefaultValueSql("''")
                    .HasComment("头像地址")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_0900_ai_ci");

                entity.Property(e => e.Mobile)
                    .IsRequired()
                    .HasColumnType("varchar(20)")
                    .HasDefaultValueSql("''")
                    .HasComment("手机号")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_0900_ai_ci");

                entity.Property(e => e.Password)
                    .IsRequired()
                    .HasColumnType("varchar(255)")
                    .HasDefaultValueSql("''")
                    .HasComment("密码")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_0900_ai_ci");

                entity.Property(e => e.UserName)
                    .IsRequired()
                    .HasColumnType("varchar(255)")
                    .HasDefaultValueSql("''")
                    .HasComment("用户名")
                    .HasCharSet("utf8mb4")
                    .HasCollation("utf8mb4_0900_ai_ci");
                entity.Property(e => e.Name)
                   .IsRequired()
                   .HasColumnType("varchar(255)")
                   .HasDefaultValueSql("''")
                   .HasComment("姓名")
                   .HasCharSet("utf8mb4")
                   .HasCollation("utf8mb4_0900_ai_ci");
                entity.Property(e => e.Vaild)
                    .HasColumnType("int")
                    .HasDefaultValueSql("1")
                    .HasComment("是否有效 1 有效");
                entity.Property(e => e.OrganizationId)
               .HasColumnType("varchar(255)")
               .HasDefaultValueSql("0")
               .HasComment("组织id");
            });


        }
    }

    /// <summary>
    /// 主库
    /// </summary>
    public class AuthCenterContext : AuthCenterAbstractContext
    {
        public AuthCenterContext(DbContextOptions<AuthCenterContext> options)
            : base(options)
        {

        }
    }
    /// <summary>
    /// 从库
    /// </summary>
    public class AuthCenterSlaveContext : AuthCenterAbstractContext
    {
        public AuthCenterSlaveContext(DbContextOptions<AuthCenterSlaveContext> options)
            : base(options)
        {

        }
    }
}
